package com.mashibing.vector;

public class Shortest_Subarray {
    //滑动窗口算法求最小子数组
    public int shortest_Subarray(int[] arr,int tar){
        int i=0;
        int sum=0;
        int subl=0;
        int result=Integer.MAX_VALUE;
        for(int j=0;j<arr.length;j++){
            sum+=arr[j];
            while(sum>=tar){
                subl=j-i+1;
                result=Math.min(result,subl);
                sum-=arr[i];
                i++;
            }
        }
        return result;
    }
}
